
finp$="video.flv"

'- numeric values into strings: empty strings means no command line entering - ffmpeg time set in seconds
fps$="15":timestart$="15":timedura$="7":gifdelay$="10"

'- xed=280:yed=192:setdisplay(xed,yed,32,1):paper(8^8-1):ink(0):pen(0):cls

ftempref$="_tmpr"

xed=320:yed=600
setdisplay(xed,yed,32,1):paper(8^8-1):ink(0):pen(0):cls



'- shell:  ffmpeg -i teste01.flv -r 4 -s 256x192 -ss 48 -t 5 _tmpr%d.png
shelout$="ffmpeg -i "+finp$
if fps$<>"" then: shelout$=shelout$+" -r "+fps$: end if
shelout$=shelout$+" -s 280x192"
if timestart$<>"" then: shelout$=shelout$+" -ss "+timestart$: end if
if timedura$<>"" then: shelout$=shelout$+" -t "+timedura$: end if
shelout$=shelout$+" "+ftempref$+"%d.png"
setcaption("ffmpeg: converting..."):shell(shelout$)
frst=0

'- counting frames
frm=1
while fileexists(ftempref$+str$(frm)+".png")<>0
  setcaption("counting frames: "+str$(frm)):frm=frm+1
wend




' finp$="cores.xpm"
'- corrigir leitura de cores (?)


' loadimage(finp$,1):pasteicon(0,400,1)

for frq=1 to frm-1:setcaption("frame "+str$(frq)+"/"+str$(frm-1))
framenm$=ftempref$+str$(frq)+".png":loadimage(framenm$,1):pasteicon(0,400,1)




for y=0 to 191
      v0=0
  for x1=0 to 39
        cflc=0
    for x2=0 to 6
        x=x2+(x1*7)
        apv=0 : cfl=0
        ind=point(x,y+400)
        b= ind mod 256: ind=int(ind/256)
        g= ind mod 256: ind=int(ind/256)
        r= ind mod 256
       prim=   (int(g/128))*4  +(int(r/128))*2  +(int(b/128)) 
          if prim=0 then : apv=0 : cfl=1 : end if   '- k
          if prim=3 then : apv=1 : cfl=0 : end if   '- m
          if prim=1 or prim=5 then : apv=1 : cfl=2 : end if   '- b
          if prim=4 then : apv=2 : cfl=0 : end if  '- g
          if prim=2 or prim=6 then : apv=2 : cfl=2 : end if   '- o
          if prim=7 then : apv=3 : cfl=1 : end if   '- w
       if(x mod 2)=0 then 
        if apv=0 or apv=2 then
          dot (x,y+200)
         end if 
        if apv=0 or apv=1 then 
          dot (x+1,y+200)
         end if 
       end if 
            cflc=cflc+cfl
    next
      if cflc<8 then
        dot (280+x1,y+200)
      end if 
  next
next

ink(0): bar(0,0,279,191)

for y=0 to 191
    ink(0xFF00FF)
  for x=0 to 279 step 2
    i=point(x,y+200) mod 256
    if i>127 then:dot(x,y): end if
  next
    ink(0x00FF00)
  for x=1 to 279 step 2
    i=point(x,y+200) mod 256
    if i>127 then:dot(x,y): end if
  next
    ink(0xFF00FF)
  for x=0 to 277 step 2
    i1=point(x,y+200) mod 256:i2=point(x+2,y+200) mod 256
    if i1>127 and i2>127 then:dot(x+1,y): end if
  next
    ink(0x00FF00)
  for x=1 to 277 step 2
    i1=point(x,y+200) mod 256:i2=point(x+2,y+200) mod 256
    if i1>127 and i2>127 then:dot(x+1,y): end if
  next
    ink(0xFFFFFF)
  for x=1 to 278
    i1=point(x,y+200) mod 256:i2=point(x+1,y+200) mod 256
    if i1>127 and i2>127 then:dot(x,y):dot(x+1,y): end if
  next
next

for y=0 to 191
  for x1=0 to 39
      q=point(280+x1,200+y) mod 256

    for x2=0 to 6
      n=point(x1*7+x2,y)

      if n=0xFF00FF and q>128 then: n=0x0000FF: end if
      if n=0x00FF00 and q>128 then: n=0xFF7F00: end if
      ink(n):dot(x1*7+x2,y)

    next
  next
next

fout$=finp$+".bmp"
' grab (1,0,0,280,192):saveimage(fout$,1)

'waitkey




grab (1,0,0,280,192):saveimage(ftempref$+str$(frq)+"_out.bmp",1)
shell("convert "+ftempref$+str$(frq)+"_out.bmp _tmpr.gif")

gifdelv=val(gifdelay$)

  if frst<>0 then:
    shell("gifsicle -l=forever -d="+str$(gifdelv)+" _tmpr1.gif _tmpr.gif > _tmpr2.gif")
  else
    shell("gifsicle -l=forever -d="+str$(gifdelv)+" _tmpr.gif > _tmpr2.gif"):frst=1
    end if

shell("rm "+ftempref$+str$(frq)+"_out.bmp "+ftempref$+str$(frq)+".png")
shell("rm _tmpr.gif _tmpr1.gif"):shell("mv _tmpr2.gif _tmpr1.gif")

cls
next

shell("mv _tmpr1.gif "+finp$+".gif"):shell("gthumb "+finp$+".gif")




